package com.all.play.myadaptertoadapter.secondadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.all.play.myadaptertoadapter.R;
import com.all.play.myadaptertoadapter.bean.MyBean;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/5/18.
 * Time: 2018/5/18  9:11
 */

public class MySecondItemOneAdapter extends RecyclerView.Adapter<MySecondItemOneAdapter.MyItemoneOneVh> {
    private Context context;
    private List<MyBean.ResultBean.ActInfoBean> act_info;

    public MySecondItemOneAdapter(Context context, List<MyBean.ResultBean.ActInfoBean> act_info) {

        this.context = context;
        this.act_info = act_info;
    }

    @Override
    public MyItemoneOneVh onCreateViewHolder(ViewGroup parent, int viewType) {

        return new MyItemoneOneVh(View.inflate(context, R.layout.item_one_one,null));
    }

    @Override
    public void onBindViewHolder(MyItemoneOneVh holder, int position) {

        MyBean.ResultBean.ActInfoBean infoBean = act_info.get(position);
        holder.tv_one_one_a.setText(act_info.get(position).getName());

        holder.setData(infoBean);

    }

    @Override
    public int getItemCount() {
        return act_info==null?0:act_info.size();
    }


    class MyItemoneOneVh extends RecyclerView.ViewHolder{
        TextView tv_one_one_a;
        public MyItemoneOneVh(View itemView) {
            super(itemView);
            tv_one_one_a=itemView.findViewById(R.id.tv_one_one_a);



        }

        public void setData(final MyBean.ResultBean.ActInfoBean infoBean) {
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(infoBean);
                }
            });
        }
    }



}
